home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / talinasm.lha / sectrect.asm < prev    next >
Encoding:
Assembly Source File  |  1992-03-19  |  1.4 KB  |  64 lines

  1. * ============================================================================ *
  2. *    SectRect: Calculate the intersection of two rectangles
  3. *
  4. *    BOOL SectRect(struct IBox *a, struct IBox *b, struct IBox *result);
  5. *                              a0              a1                   a2
  6. * ============================================================================ *
  7.  
  8.             include        'intuition/intuition.i'
  9.  
  10.             SECTION        sectrect.asm,CODE
  11.  
  12.             xdef        _SectRect
  13. _SectRect:            ; (a0, a1, a2)
  14.  
  15. ;    x1 = MAX(a->Left, b->Left);
  16.  
  17.             move.w        ibox_Left(a0),d0
  18.             move.w        ibox_Left(a1),d1
  19.             move.w        d0,ibox_Left(a2)
  20.             cmp.w        d0,d1
  21.             blt.s        1$
  22.             move.w        d1,ibox_Left(a2)
  23. 1$
  24.  
  25. ;    x2 = MIN(a->Left + a->Width, b->Left + b->Width) - x1;
  26.  
  27.             add.w        ibox_Width(a0),d0
  28.             add.w        ibox_Width(a1),d1
  29.             cmp.w        d0,d1
  30.             bgt.s        2$
  31.             move.w        d1,d0
  32. 2$            sub.w        ibox_Left(a2),d0
  33.             bpl.s        20$
  34.             moveq        #0,d0
  35. 20$            move.w        d0,ibox_Width(a2)
  36.  
  37. ;    y1 = MAX(a->Top, b->Top);
  38.  
  39.             move.w        ibox_Top(a0),d0
  40.             move.w        ibox_Top(a1),d1
  41.             move.w        d0,ibox_Top(a2)
  42.             cmp.w        d0,d1
  43.             blt.s        3$
  44.             move.w        d1,ibox_Top(a2)
  45. 3$
  46. ;    y2 = MIN(a->Top + a->Height, b->Top + b->Height) - y1;
  47.  
  48.             add.w        ibox_Height(a0),d0
  49.             add.w        ibox_Height(a1),d1
  50.             cmp.w        d0,d1
  51.             bgt.s        4$
  52.             move.w        d1,d0
  53. 4$            sub.w        ibox_Top(a2),d0
  54.             bpl.s        40$
  55.             moveq        #0,d0
  56. 40$            move.w        d0,ibox_Height(a2)
  57.  
  58.             beq.s        50$                        ; return TRUE if non-zero interior
  59.             tst.w        ibox_Width(a2)
  60.             beq.s        50$
  61.             moveq        #1,d0
  62. 50$
  63.             rts
  64.